package ru.surfstudio.graduate;


import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;

import android.app.Application;

public class WSApplication extends Application {
	
	private static final int TIMEOUT_INTERVAL = 20000; //msec
	
    private HttpComponentsClientHttpRequestFactory clientHttpRequestFactory;

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        shutdownHttpClient();
    }

    public ClientHttpRequestFactory getClientHttpRequestFactory() {
        if (clientHttpRequestFactory == null) {
            clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory();
            clientHttpRequestFactory.setReadTimeout(TIMEOUT_INTERVAL);
            // clientHttpRequestFactory.setHttpClient(HttpClientInitializer.getHttpClient(this));
        }
        return clientHttpRequestFactory;
    }

    private void shutdownHttpClient() {
        if (clientHttpRequestFactory != null) {
            clientHttpRequestFactory.destroy();
        }
    }
    
}
